package com.project.dao.impls;

import com.project.bean.ClassBean;
import com.project.bean.StudentBean;
import com.project.dao.StudentDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * dao实现
 */
public class StudentDaoImpls extends BaseDao implements StudentDao {

    @Override
    public List<ClassBean> findAll() {
        List<ClassBean> list = new ArrayList<>();
        this.setConnection();
        try {
            ps = con.prepareStatement("select c.c_name,s.s_name from t_student s, t_calss c where s.fk_classId=c.pk_classId");
            rs = ps.executeQuery();
            while (rs.next()){
                StudentBean studentBean = new StudentBean();
                studentBean.setNam(rs.getString(2));
                ClassBean classBean = new ClassBean();
                classBean.setClassName(rs.getString(1));
                classBean.setStudentBean(studentBean);
                list.add(classBean);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            this.closeConnection();
        }

        return list;
    }

    public static void main(String[] args) {
        StudentDao dao = new StudentDaoImpls();
        System.out.println(dao.findAll());
    }
}


